package com.elloe.数组.长度最小的子数组;

/**
 * @author ElloeStudy(Sifa Zhang)
 * @create 2022-04-02 21:44
 * To: 真常应物，真常得性，常清常静，常清静矣
 */
public class MinSubArrayLen {
    public static void main(String[] args) {
        // 测试集
        int[] nums = {2,3,1,2,4,3};
        int s = 7;

        int result = Integer.MAX_VALUE;  // 判断是否存在字符串大于指定值
        int left = 0;
        int sum = 0;
        for (int right = 0; right < nums.length; right++) {
            sum += nums[right];
            while (sum >= s){
                result = Math.min(result, right-left+1);
                sum -= nums[left++];
            }
        }
        System.out.println(result == Integer.MAX_VALUE ? 0 : result);
    }
}
